home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8616 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  55 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Why doesn't this work?
  5. Date: Tue, 05 Mar 96 12:54:12 GMT
  6. Organization: none
  7. Message-ID: <826030452snz@genesis.demon.co.uk>
  8. References: <1996Mar4.161412.137442@forest>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <1996Mar4.161412.137442@forest> ebromber@forest.drew.edu  writes:
  15.  
  16. ...
  17.  
  18. > main();
  19. > {
  20.  
  21. This is a syntax error and won't compile (at least not without an error).
  22. Remove the ;
  23.  
  24. ...
  25.  
  26. >        while (c=getch() !='\n')
  27. >        {       count++;
  28. >                pass[count]=c;
  29.  
  30. You should store the character before you increment count. As it stands
  31. this stores characters in pass[1] through to pass[4].
  32.  
  33. ...
  34.  
  35. >                if (real[i]=pass[i]) error++;
  36.  
  37. Make that:
  38.  
  39.                  if (real[i]==pass[i]) error++;
  40.  
  41. Many compilers can warn you about this if you set an appropriate warning
  42. level. Also note that the entire comparison loop can be replaced with a
  43. single memcmp() call.
  44.  
  45. >        if (error>0) {printf("\nWRONG PASSWORD\n"); main();}
  46.  
  47. Every time the user gets the password wrong you'll eat up more stack space
  48. (unless your compiler can optimise tail end recursion). Use a loop instead.
  49.  
  50. -- 
  51. -----------------------------------------
  52. Lawrence Kirby | fred@genesis.demon.co.uk
  53. Wilts, England | 70734.126@compuserve.com
  54. -----------------------------------------
  55.